/**
 * \file paged.h
 * \author Davide Gessa
 * \date 10-12-09
 */
/*
 * Gestore della memoria paginata
 * 	Consente l'allocazione di pagine virtuali, utilizzabili quindi dai processi
 *  in usermode.
 */
#ifndef PAGED_H
#define PAGED_H

#include <arch.h>
#include <types.h>


typedef struct
{
	uint32_t present:1;
	uint32_t read_write:1;
	uint32_t user_super:1;
	uint32_t write_through:1;
	uint32_t cache_disabled:1;
	uint32_t accessed:1;
	uint32_t always0:1;
	uint32_t page_size:1; // 0 = 4 kb
	uint32_t ignored:1;
	uint32_t aviable:3;
	uint32_t page_table_addr:20;
} page_dir_entry_t;


/*
 * Page Table
 */
typedef struct
{
	uint32_t present:1;	
	uint32_t read_write:1;
	uint32_t user_super:1;
	uint32_t write_through:1;
	uint32_t chache_disabled:1;
	uint32_t accessed:1;
	uint32_t dirty:1;
	uint32_t always0:1;
	uint32_t global:1;
	uint32_t aviable:3;
	uint32_t phys_page_addr:20;
} page_table_entry_t;

typedef struct
{
	page_dir_entry_t data[1024];
} page_dir_t;

typedef struct
{
	page_table_entry_t data[1024];
} page_table_t;


void *page_get_phys_addr(void *);
void page_map_page(void *, void *, uint32_t);
void page_unmap_page(void *);
void page_fault_handler(regs_t *);

#endif
